/**
 * 二维地图上有多个H，曼哈顿距离不超过D的都可以成为H
 * 问一共有多少个H
 * 成批扩展BFS即可
 */
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;

using Real = long double;
using llt = long long;
using vi = vector<int>;
using vll = vector<llt>;
using pii = pair<int, int>;
using pll = pair<llt, llt>;

int H, W, D;
vector<string> Board;
vector<vi> Flag;

void work(){
    cin >> H >> W >> D;
    Board.assign(H, {});
    for(auto & s : Board) cin >> s;

    Flag.assign(H, vi(W, 0));
    queue<pii> Q;

    for(int i=0;i<H;++i)for(int j=0;j<W;++j){
        if('H' == Board[i][j]){
            Q.push({i, j});
            Flag[i][j] = 1;
        }
    }

    static const int DR[] = {-1, 1, 0, 0};
    static const int DC[] = {0, 0, -1, 1};

    for(int d=0;d<D;++d){
        auto sz = Q.size();
        if(0 == sz) break;

        while(sz--){
            auto h = Q.front(); Q.pop();
            for(int nr,nc,i=0;i<4;++i){
                nr = h.first + DR[i];
                nc = h.second + DC[i];
                if(0 <= nr and nr < H and 0 <= nc and nc < W and '#' != Board[nr][nc] and 0 == Flag[nr][nc]){
                    Flag[nr][nc] = 1;
                    Q.push({nr, nc});
                }
            }
        }
    }

    int ans = 0;
    for(const auto & v : Flag) ans += accumulate(v.begin(), v.end(), 0);
    cout << ans << endl;
    return;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);	

    int nofkase = 1;
	// cin >> nofkase;
	while(nofkase--) work();
	return 0;
}